package org.railage.server.entities;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.railage.common.dto.TripDTO;

/**
 * Trip entity
 * 
 * @author Cyril Fertikov
 * 
 */
@Entity
@Table(name = "trip")
public class Trip implements Serializable {
	private static final long serialVersionUID = -390328166316032832L;

	@Id
	@GeneratedValue
	@Column(name = "id")
	private int id;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "route_id")
	private Route route;

	@Column(name = "seats")
	private int seats;

	@Column(name = "start")
	private Timestamp start;

	public Trip() {

	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Route getRoute() {
		return route;
	}

	public void setRoute(Route route) {
		this.route = route;
	}

	public int getSeats() {
		return seats;
	}

	public void setSeats(int seats) {
		this.seats = seats;
	}

	public Timestamp getStart() {
		return start;
	}

	public void setStart(Timestamp start) {
		this.start = start;
	}

	public TripDTO toDTO() {
		TripDTO dto = new TripDTO();
		dto.setId(id);
		dto.setRouteName(route.getName());
		dto.setSeats(seats);
		dto.setStart(start);
		return dto;
	}

	@Override
	public String toString() {
		return "Trip [id=" + id + ", route=" + route + ", seats=" + seats
				+ ", start=" + start + "]";
	}

}
